package com.example.hellowordl; // 替换为你的包名

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private EditText etUsername, etPassword;
    private Button btnLogin, btnRegister;
    private ProgressBar pbLoading;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化控件
        etUsername = findViewById(R.id.et_username);
        etPassword = findViewById(R.id.et_password);
        btnLogin = findViewById(R.id.btn_login);
        btnRegister = findViewById(R.id.btn_register);
        pbLoading = findViewById(R.id.pb_loading);

        // 登录按钮点击事件
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoading();
                // 3秒后隐藏进度条并提示登录成功
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        finishLoading();
                        Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    }
                }, 3000);
            }
        });

        // 注册按钮点击事件
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoading();
                // 3秒后隐藏进度条并提示注册相关（这里暂同登录提示，可根据需求修改）
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        finishLoading();
                        Toast.makeText(MainActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                    }
                }, 3000);
            }
        });
    }

    // 显示进度条
    private void showLoading() {
        pbLoading.setVisibility(View.VISIBLE);
        btnLogin.setEnabled(false);
        btnRegister.setEnabled(false);
    }

    // 隐藏进度条，恢复按钮状态
    private void finishLoading() {
        pbLoading.setVisibility(View.GONE);
        btnLogin.setEnabled(true);
        btnRegister.setEnabled(true);
    }
}